import { Order } from '@app/database/schemas/order.schema';
import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  UseGuards,
  Query,
} from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
import { OrdersService } from './orders.service';

@UseGuards(AuthGuard('jwt'))
@ApiBearerAuth()
@ApiTags('后台订单模块')
@Controller('/admin/orders')
export class OrdersController {
  constructor(private readonly ordersService: OrdersService) {}

  @ApiOperation({ summary: '创建订单' })
  @Post()
  create(@Body() order: Order) {
    return this.ordersService.create(order);
  }

  @ApiOperation({ summary: '订单列表' })
  @Get()
  findAll(@Query() query: any) {
    return this.ordersService.findAll(query);
  }

  @ApiOperation({ summary: '查询订单' })
  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.ordersService.findOne(id);
  }

  @ApiOperation({ summary: '订单更新' })
  @Patch(':id')
  update(@Param('id') id: string, @Body() order: Order) {
    return this.ordersService.update(id, order);
  }

  @ApiOperation({ summary: '删除订单' })
  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.ordersService.remove(id);
  }

  @ApiOperation({ summary: '订单配置' })
  @Post('options')
  orderConfigs(): any {
    return this.ordersService.option();
  }
}
